'use strict';

const moment = require('moment');

module.exports = app => {
  const { Sequelize } = app;

  const UsersGoods = app.model.define('UsersGoods', {
    userId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      primaryKey: true,
      onDelete: 'CASCADE',
      onUpdate: 'CASCADE',
      references: {
        model: 'Users',
        key: 'id'
      }
    },
    goodsId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      primaryKey: true,
      onDelete: 'CASCADE',
      onUpdate: 'CASCADE',
      references: {
        model: 'Goods',
        key: 'id'
      }
    },
    goodsPrizeId: {
      type: Sequelize.INTEGER,
      allowNull: false,
      primaryKey: true,
      onDelete: 'CASCADE',
      onUpdate: 'CASCADE',
      references: {
        model: 'GoodsPrizes',
        key: 'id'
      }
    },
    number: {
      allowNull: false,
      type: Sequelize.INTEGER,
      defaultValue: '0'
    },
    status: {
      allowNull: false,
      type: Sequelize.INTEGER(1),
      comment: '0、参与的抽奖 1、发起的抽奖 2、已经中奖',
      defaultValue: '0'
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.BIGINT(13),
      get() { return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm') }
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.BIGINT(13),
      get() { return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm') }
    },
  }, {
    timestamps: false,
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci',
    comment: '用户抽奖表',
  });

  return UsersGoods;

};